package com.imagecollector.controller.common;


import com.imagecollector.common.R;
import com.imagecollector.domain.entity.District;
import com.imagecollector.domain.vo.DistrictVO;
import com.imagecollector.service.IDistrictService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author wrf
 * @since 2024-07-31
 */
@Api(tags = "地区相关接口")
@RestController
@RequestMapping("user/district")
public class DistrictController {

    @Autowired
    private IDistrictService districtService;

    @GetMapping("childrenList")
    @ApiOperation(value = "获取该地区的下级地区列表")
    public R provinces(@RequestParam("districtId") @NotNull Integer districtId) {
        DistrictVO res = districtService.childrenList(districtId);
        return R.success().data("data", res);
    }

    @GetMapping("getAllProvinces")
    @ApiOperation(value = "获取所有省份")
    public R getAllProvinces() {
        List<District> res = districtService.getAllProvinces();
        return R.success().data("data", res);
    }

}
